// The following example creates a marker in Stockholm, Sweden
// using a DROP animation. Clicking on the marker will toggle
// the animation between a BOUNCE animation and no animation.

var stockholm = new google.maps.LatLng(59.32522, 18.07002);
var parliament = new google.maps.LatLng(59.327383, 18.06747);
var marker;
var map;
var index = 1;

//var array = [
//{lat:'17.675754933140635', lng:' 105.7876968383789'},
//{lat:'17.658089882469447', lng:' 105.81275939941406'},
//{lat:'17.6410774541174', lng:' 105.84022521972656'},
//{lat:'17.635188162239857', lng:' 105.84571838378906'},
//{lat:'17.628971478704955', lng:' 105.85018157958984'},
//{lat:'17.620464090732245', lng:' 105.86734771728516'},
//{lat:'17.60672053960089', lng:' 105.87833404541016'},
//{lat:'17.597230334108467', lng:' 105.88794708251953'},
//{lat:'17.581521312310567', lng:' 105.89996337890625'},
//{lat:'17.567774798594957', lng:' 105.91266632080078'},
//{lat:'17.547153070268138', lng:' 105.93017578125'},
//{lat:'17.521618154919032', lng:' 105.95043182373047'},
//{lat:'17.499026580457638', lng:' 105.9686279296875'},
//{lat:'17.474139856580738', lng:' 105.9902572631836'},
//{lat:'17.45317997550694', lng:' 106.00845336914062'},
//{lat:'17.429597227585322', lng:' 106.02699279785156'},
//{lat:'17.41354611437445', lng:' 106.04209899902344'},
//{lat:'17.395200257973162', lng:' 106.05789184570312'},
//{lat:'17.37292067241041', lng:' 106.07711791992188'},
//{lat:'17.354570742839186', lng:' 106.1063003540039'},
//{lat:'17.33556352232451', lng:' 106.13582611083984'},
//{lat:'17.297543177922922', lng:' 106.17496490478516'},
//{lat:'17.275579570113493', lng:' 106.19659423828125'},
//{lat:'17.261810002833062', lng:' 106.22303009033203'},
//{lat:'17.24738363891895', lng:' 106.23950958251953'},
//{lat:'17.264105002145506', lng:' 106.2872314453125'},
//{lat:'17.294265193878292', lng:' 106.2872314453125'},
//{lat:'17.259187111498402', lng:' 106.31195068359375'},
//{lat:'17.240825827903386', lng:' 106.3260269165039'},
//{lat:'17.199506265278227', lng:' 106.32259368896484'},
//{lat:'17.170642685078217', lng:' 106.33769989013672'},
//{lat:'17.141446539232547', lng:' 106.36001586914062'},
//{lat:'17.0997766779308', lng:' 106.3970947265625'},
//{lat:'17.02658578826762', lng:' 106.4297103881836'},
//{lat:'16.9980237218682', lng:' 106.5509033203125'},
//{lat:'16.8088136303751', lng:' 106.55261993408203'},
//{lat:'16.69342096180891', lng:' 106.55193328857422'},
//{lat:'16.557885360129827', lng:' 106.67278289794922'},
//{lat:'16.46967017557191', lng:' 106.78401947021484'}
//            ];

var array = [{lat: '10.941037600000001',
	lng: '106.7664501'}];

//var selectedArray = [{lat:'17.675754', lng:'105.787696'}, {lat:'17.658089', lng:'105.812759'}, {lat:'17.659578', lng:'105.813860'}, {lat:'17.658099', lng:'105.812784'}, {lat:'17.641077', lng:'105.840225'}, {lat:'17.640424', lng:'105.839783'}, {lat:'17.638971', lng:'105.838672'}, {lat:'17.628971', lng:'105.850181'}, {lat:'17.632190', lng:'105.853432'}, {lat:'17.630783', lng:'105.852254'}, {lat:'17.620464', lng:'105.867347'}, {lat:'17.617892', lng:'105.865676'}, {lat:'17.616507', lng:'105.864471'}, {lat:'17.429597', lng:'106.026992'}, {lat:'17.430890', lng:'106.028680'}, {lat:'17.429761', lng:'106.027210'}, {lat:'17.372920', lng:'106.077117'}, {lat:'17.378025', lng:'106.082853'}, {lat:'17.376748', lng:'106.081526'}, {lat:'17.335563', lng:'106.135826'}, {lat:'17.331329', lng:'106.132621'}, {lat:'17.329930', lng:'106.131438'}, {lat:'17.275579', lng:'106.196594'}, {lat:'17.280904', lng:'106.201883'}, {lat:'17.279557', lng:'106.200633'}, {lat:'17.261810', lng:'106.223030'}, {lat:'17.260021', lng:'106.221935'}, {lat:'17.258540', lng:'106.220868'}, {lat:'17.247383', lng:'106.239509'}, {lat:'17.263508', lng:'106.245334'}, {lat:'17.261711', lng:'106.245405'}, {lat:'17.264105', lng:'106.287231'}, {lat:'17.282820', lng:'106.274264'}, {lat:'17.281567', lng:'106.275615'}, {lat:'17.294265', lng:'106.287231'}, {lat:'17.258833', lng:'106.318341'}, {lat:'17.257072', lng:'106.317956'}, {lat:'17.240825', lng:'106.326026'}, {lat:'17.233315', lng:'106.310979'}, {lat:'17.232712', lng:'106.309204'}, {lat:'17.199506', lng:'106.322593'}, {lat:'17.200030', lng:'106.333764'}, {lat:'17.199747', lng:'106.331905'}, {lat:'17.170642', lng:'106.337699'}, {lat:'17.172499', lng:'106.341107'}, {lat:'17.171556', lng:'106.339504'}, {lat:'17.141446', lng:'106.360015'}, {lat:'17.142987', lng:'106.362089'}, {lat:'17.141862', lng:'106.360620'}, {lat:'17.099776', lng:'106.397094'}, {lat:'17.094582', lng:'106.389550'}, {lat:'17.093679', lng:'106.387921'}, {lat:'17.026585', lng:'106.429710'}, {lat:'17.055260', lng:'106.466077'}, {lat:'17.053781', lng:'106.465006'}, {lat:'16.998023', lng:'106.550903'}, {lat:'16.921996', lng:'106.489847'}, {lat:'16.921141', lng:'106.488192'}, {lat:'16.808813', lng:'106.552619'}, {lat:'16.808808', lng:'106.552483'}, {lat:'16.808803', lng:'106.550602'}, {lat:'16.693420', lng:'106.551933'}, {lat:'16.704310', lng:'106.603737'}, {lat:'16.703559', lng:'106.602030'}, {lat:'16.557885', lng:'106.672782'}, {lat:'16.567661', lng:'106.683798'}, {lat:'16.566392', lng:'106.682466'}];
var selectedArray = [{lat: '10.941037600000001',
	lng: '106.7664501'}];
function placeMarker(location) {
	var marker = new google.maps.Marker({
		position : location,
		map : map,
		title : 'index:' + index + '(' + location.lat() +','+location.lng()+')'
	});
}


function initialize() {
	var mapOptions = {
		zoom : 13,
		center : new google.maps.LatLng(array[0].lat, array[0].lng)
	};

	map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
	for (var int = 0; int < array.length; int++) {
		
		marker = new google.maps.Marker({
			map : map,
			draggable : true,
			animation : google.maps.Animation.DROP,
			position :  new google.maps.LatLng(array[int].lat, array[int].lng),
			title : 'index:' + index + '(' + array[int].lat +','+array[int].lng+')'
		});
		google.maps.event.addListener(marker, 'click', toggleBounce);
		index++;
	}
	

	for (var int = 0; int < selectedArray.length; int++) {

		marker = new google.maps.Marker({
			map : map,
			icon: 'http://maps.google.com/mapfiles/ms/icons/blue-dot.png',
			draggable : true,
			animation : google.maps.Animation.DROP,
			position : new google.maps.LatLng(selectedArray[int].lat, selectedArray[int].lng),
			title : 'index:' + index + '(' + selectedArray[int].lat + ','
					+ selectedArray[int].lng + ')'
		});
		google.maps.event.addListener(marker, 'click', toggleBounce);
		index++;
	}
	
	google.maps.event.addListener(map, 'click', function(event) {
		console.info(event.latLng.toString())
		placeMarker(event.latLng);
		index++;
	});
	
}

function toggleBounce() {

	if (marker.getAnimation() != null) {
		marker.setAnimation(null);
	} else {
		marker.setAnimation(google.maps.Animation.BOUNCE);
	}
}

google.maps.event.addDomListener(window, 'load', initialize);




